//
//  AboutUsView.swift
//  E-CycleForShop
//
//  Created by enghou on 17/3/10.
//  Copyright © 2017年 xyxorigation. All rights reserved.
//

import UIKit

class AboutUsView: BaseView {

    
    var descUrl : String = ""
    //暂时将logo，客服电话，邮箱写死，仅仅留下企业介绍是动态
    override init(frame: CGRect) {
        super.init(frame: frame)
        configStableView()
    }
    
    //配置固定视图
    private func configStableView() -> Void {
        self.backgroundColor = UIColor.colorWithHexString(hex: "f3f3f5")
        let imageView = UIImageView.init()
        imageView.frame = CGRect.init(origin: CGPoint.init(x: YXDeviceWidth / 2 - 70 * YXWidthScale, y: 86 * YXHeightScale), size: CGSize.init(width: 140 * YXWidthScale, height: 140 * YXHeightScale))
        imageView.image = UIImage.load(name: "icon_aboutus")
        imageView.layer.cornerRadius = 2 * YXButtonCorner
        imageView.layer.masksToBounds = true
        self.addSubview(imageView)
        let first = baseSection(title: "客服电话", content: "0571-86686688", right: false)
        first.frame = CGRect.init(origin: CGPoint.init(x: 0, y: 314 * YXHeightScale), size: CGSize.init(width: YXDeviceWidth, height: 88 * YXHeightScale))
        self.addSubview(first)
        
        let second = baseSection(title: "邮箱", content: "lizhenfan@sina.com", right: false)
        second.frame = CGRect.init(origin: CGPoint.init(x: 0, y: 402 * YXHeightScale), size: CGSize.init(width: YXDeviceWidth, height: 88 * YXHeightScale))
        self.addSubview(second)
        
        let third = baseSection(title: "企业介绍", content: "", right: true)
        third.frame = CGRect.init(origin: CGPoint.init(x: 0, y: 490 * YXHeightScale), size: CGSize.init(width: YXDeviceWidth, height: 87 * YXHeightScale))
        self.addSubview(third)
        
        let bottomLbl = UILabel.init()
        bottomLbl.textColor = UIColor.colorWithHexString(hex: "909090")
        bottomLbl.text = "Copyright © 2016-2017杭州云曦科技有限公司"
        bottomLbl.numberOfLines = 2
        bottomLbl.font = UIFont.systemFont(ofSize: 20 * YXWidthScale)
        let size = "Copyright © 2016-2017".StringSize(font: bottomLbl.font)
        bottomLbl.frame = CGRect.init(origin: CGPoint.init(x: YXDeviceWidth / 2 - size.width / 2, y: YXDeviceHeight - 60 * YXHeightScale - size.height - 64), size: CGSize.init(width: size.width, height: 2 * size.height))
        bottomLbl.textAlignment = .center
        self.addSubview(bottomLbl)
    }
    
    func baseSection(title : String,content : String,right : Bool) -> UIView {
        let view = UIView.init()
        view.backgroundColor = UIColor.white
        let label = UILabel.init()
        label.textColor = UIColor.black
        label.text = title
        label.font = UIFont.systemFont(ofSize: 28 * YXWidthScale)
        let size = title.StringSize(font: label.font)
        label.frame = CGRect.init(origin: CGPoint.init(x: 48 * YXWidthScale, y: 44 * YXHeightScale - size.height / 2), size: size)
        view.addSubview(label)
        
        let label1 = UILabel.init()
        label1.textColor = UIColor.colorWithHexString(hex: "646464")
        label1.font = label.font
        let size1 = content.StringSize(font: label1.font)
        label1.frame = CGRect.init(origin: CGPoint.init(x: YXDeviceWidth - 48 * YXWidthScale - size1.width, y: label.top()), size: size1)
        label1.text = content
        view.addSubview(label1)
        
        let line = UIView.init()
        line.backgroundColor = UIColor.colorWithHexString(hex: "ececec")
        line.frame = CGRect.init(origin: CGPoint.init(x: label.left(), y: 87 * YXHeightScale), size: CGSize.init(width: 1000, height: YXHeightScale))
        view.addSubview(line)
        
        if right == true {
            //24 40
            //icon_enter
            let img = UIImageView.init()
            img.frame = CGRect.init(origin: CGPoint.init(x: YXDeviceWidth - 72 * YXWidthScale, y: 24 * YXHeightScale), size: CGSize.init(width: 24 * YXWidthScale, height: 40 * YXHeightScale))
            img.image = UIImage.load(name: "icon_enter")
            view.addSubview(img)
            
            let button = Button.init(type: .system)
            button.frame = CGRect.init(origin: CGPoint.init(x: 0, y: 0), size: CGSize.init(width: YXDeviceWidth, height: 88 * YXHeightScale))
            let imag = UIImage.image(color: UIColor.clear, size: button.frame.size)
            button.setBackgroundImage(imag, for: .normal)
            let imag1 = UIImage.image(color: UIColor.init(white: 0, alpha: 0.3), size: button.frame.size)
            button.setBackgroundImage(imag1, for: .highlighted)
            view.addSubview(button)
            button.addTarget(self, action: #selector(push), for: .touchUpInside)
        }
        
        return view
    }
    
    @objc func push() -> Void {
        let enterprise = EnterpriseDescViewController.init()
        enterprise.url = descUrl
        enterprise.hidesBottomBarWhenPushed = true
        self.owner?.navigationController?.pushViewController(enterprise, animated: true)
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    deinit {
        print("AboutUsView被释放")
    }
    
    /*
    // Only override draw() if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    override func draw(_ rect: CGRect) {
        // Drawing code
    }
    */

}
